{% extends "base.html" %} {% block title %}社区交流 - 运动健康管理系统{%
endblock %} {% block content %}
<div class="container py-5">
  <div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="mb-0"><i class="bi bi-people"></i> 社区交流</h1>
    {% if current_user.is_authenticated %}
    <a href="{{ url_for('create_post') }}" class="btn btn-primary">
      <i class="bi bi-plus-circle"></i> 发布新帖子
    </a>
    {% else %}
    <a href="{{ url_for('login') }}" class="btn btn-outline-primary">
      登录后发帖
    </a>
    {% endif %}
  </div>

  {% if posts %}
  <div class="card shadow">
    <div class="list-group list-group-flush">
      {% for post in posts %}
      <a
        href="{{ url_for('post_detail', post_id=post.id) }}"
        class="list-group-item list-group-item-action">
        <div class="d-flex w-100 justify-content-between">
          <h5 class="mb-1">{{ post.title }}</h5>
          <small class="text-muted"
            >{{ post.created_at.strftime('%Y-%m-%d %H:%M') }}</small
          >
        </div>
        <p class="mb-1">{{ post.content|truncate(100) }}</p>
        <div class="d-flex justify-content-between align-items-center">
          <small class="text-muted">
            作者: {{ post.user.username }} |
            <i class="bi bi-eye"></i> {{ post.view_count }} |
            <i class="bi bi-chat"></i> {{ post.comments|length }} |
            <i class="bi bi-heart"></i> {{ post.like_count }}
          </small>
        </div>
      </a>
      {% endfor %}
    </div>
  </div>
  {% else %}
  <div class="alert alert-info">
    <p class="mb-0">暂无帖子，成为第一个发帖的人吧！</p>
  </div>
  {% endif %}
</div>
{% endblock %}
